// Control variables.
IntList pp_keyLog;
int pp_keyLogLength, pp_keyReleased;

void pp_initControls() {
  pp_keyLogLength = 10;
  
  // Initiate keyLog.
  pp_keyLog = new IntList();
  for (int i = 0; i < pp_keyLogLength; i++) {
    pp_keyLog.append(0);
  }
}

void keyPressed() {
  pp_keyLog.append(keyCode);
  pp_keyLog.remove(0);
  
  // Trigger key event for all gameObjects.
  for (pp_gameObject obj : pp_objects) {
    obj.keyPressed();
  }
}

void keyReleased() {
  pp_keyReleased = keyCode;
  
  // Trigger key event for all gameObjects.
  for (pp_gameObject obj : pp_objects) {
    obj.keyReleased();
  }
}

void mousePressed() {
  // Trigger mouse event for all gameObjects.
  for (pp_gameObject obj : pp_objects) {
    obj.mousePressed();
  }
}

void mouseReleased() {
  // Trigger mouse event for all gameObjects.
  for (pp_gameObject obj : pp_objects) {
    obj.mouseReleased();
  }
}

int pp_lastKey() {
  return pp_keyLog.get(pp_keyLog.size() - 1);
}
